package com.dfrz.hospital.controller.patient;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dfrz.hospital.pojo.Member;
import com.dfrz.hospital.service.MemberService;
import com.dfrz.hospital.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private MemberService memberService;

    /**
     * 获取分页数据
     * @param pageNum 当前页数
     * @param pageSize 每页大小
     * @param search 查询条件
     * @return 分页数据
     */
    @GetMapping("/getPage")
    public R<Page<Member>> getPage(Integer pageNum,Integer pageSize,String search){
        Page<Member> pageInfo = new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<Member> qw = new LambdaQueryWrapper<>();
        qw.like(StringUtils.isNotBlank(search),Member::getName,search);
        memberService.page(pageInfo,qw);
        return R.success(pageInfo);
    }

    /**
     * 获取所有病人医生信息
     * @return 病人医生数据列表
     */
    @GetMapping("/getMembers")
    public R<List<Member>> getPage(){
        List<Member> members = memberService.list();
        return R.success(members);
    }

}
